﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace RiskMan.DataClass.Models.Plaza_II.FortsFutorderBookRepl
{
    /// <summary>
    /// Таблица 15. Поля таблицы info - Информация о стаканах
    /// </summary>
    public class Info: INotifyPropertyChanged
    {
        #region private

        private long _replId;
        private long _replRev;
        private long _replAct;
        private long _infoId;
        private long _logRev;
        private DateTime _moment;

        #endregion

        #region public

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplId
        {
            get { return _replId; }
            set
            {
                if (_replId != value)
                {
                    _replId = value;
                    RaisePropertyChanged("ReplId");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplRev
        {
            get { return _replRev; }
            set
            {
                if (_replRev != value)
                {
                    _replRev = value;
                    RaisePropertyChanged("ReplRev");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplAct
        {
            get { return _replAct; }
            set
            {
                if (_replAct != value)
                {
                    _replAct = value;
                    RaisePropertyChanged("ReplAct");
                }
            }
        }
        
        /// <summary>
        /// Уникальный ключ
        /// </summary>
        public long InfoId
        {
            get { return _infoId; }
            set
            {
                if (_infoId != value)
                {
                    _infoId = value;
                    RaisePropertyChanged("InfoId");
                }
            }
        }
        
        /// <summary>
        /// Ревизия по фьючерсам на момент формирования снэпшота

        /// </summary>
        public long LogRev
        {
            get { return _logRev; }
            set
            {
                if (_logRev != value)
                {
                    _logRev = value;
                    RaisePropertyChanged("LogRev");
                }
            }
        }
        /// <summary>
        /// Время формирования снэпшота
        /// </summary>
        public DateTime Moment
        {
            get { return _moment; }
            set
            {
                if (_moment != value)
                {
                    _moment = value;
                    RaisePropertyChanged("Moment");
                }
            }
        }
           

        #endregion

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region processing
        public static Info ParseInfo(Dictionary<String, String> relation)
        {
            Info tmp = new Info();
            tmp.Parse(relation);
            return tmp;
        }

        public void Parse(Dictionary<String, String> relation)
        {
            foreach (String field in relation.Keys)
            {
                String value = relation[field];

                switch (field)
                {
                    case "replID": long.TryParse(value, out _replId); break;
                    case "replRev": long.TryParse(value, out _replRev); break;
                    case "replAct": long.TryParse(value, out _replAct); break;
                    case "info_id": long.TryParse(value, out _infoId); break;
                    case "log_rev": long.TryParse(value, out _logRev); break;
                    case "moment": DateTime.TryParse(value, out _moment); break; 

                };
            }
        }

        public static void AddValueToObsColInfo(Info inst)
        {
            MainWindow.StaticLevel._dataProvider.InfoList.Add(inst);
        }
        #endregion
    }
}
